home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
curses.arc
/
curses.doc
< prev
next >
Wrap
Text File
|
1987-08-24
|
33KB
|
851 lines
The CURSES screen updating and cursor movement package.
A collection of C-functions for Atari ST-series computers
Version 1.0
R. van 't Veen
This document describes a set of C-functions which allow the user
easier design of full-screen applications. This package is intended for
programs that perform graphics-like operations on terminal screens.
It is largely compatible with the UN*X curses(3x) package. This document
provides pointers to its use, a little detail about its inner workings and it
stresses differences between the UN*X-implementation and the Atari-ST series
implementation.
Introduction.
This package was born out of my desire to make more programs available for
UN*X also available on my Atari. A side-effect of this is that it provides
easier screen updating than by means of sending escape codes. The package is
also quite fast, timing of a sample application yielded a rate of about
90 kilobaud per second.
Terminology.
Throughout this document the following words will be used frequently :
WINDOW An internal representation of what a section of the terminal
screen may eventually look like. A window is a rectangular
array, which may be as big as the terminal screen or even as
small as a single character.
TERMINAL Or terminal screen, the packages idea of what the Atari's VT52
emulation looks like. If everything is allright this is what you
see. The terminal screen is a special screen.
SCREEN A screen is an element of the set of windows that are as large as
the terminal screen. One screen, called stdscr, is already
provided for.
Using the package.
To use the package, include the file "curses.h" in your source. This gives
you the types and definitions necessary to be able to use it. After compilation
one should link with the file containing the compiled curses-source, as well as
with the object-file or library giving you access to the system calls,
gemdos, bios and xbios. You also should link in a file giving you access
to the malloc() and free() calls. ( Note : this is not the GEMDOS Malloc/Mfree
pair, but a malloc() and free(), which should be contained in any decent
standard C-function library. GEMDOS Malloc/Mfree are very buggy indeed.)
There is a difference with UN*X here : the UN*X-curses includes stdio.h
and sgtty.h, whereas Atari-curses includes portab.h and stdio.h. This should
give you the definitions for BYTE, WORD and LONG.
Some compilers supply default startup files that don't supply enough heap space
to run curses in, you should adapt these startup files to your liking.
Installing the package.
Compile the file "curses.c" with your favorite C-compiler, to create an
object-file or library, whatever you prefer. Curses.c includes "portab.h"
for BYTE, WORD, LONG, and NULL definitions, osbind.h for system-call macros
and curses.h for its own definitions. Remember curses.h also includes stdio.h.
The code should be portable between various brands of compilers. Forget about
warnings like : warning : pointer substraction yields a long result.
Not all compilers adhere to Kernighan and Ritchie standards in this respect.
The meaning of each of the constants is given in the table below. In another
table the used system call macro's are given.
+---------------+----------------------------------------------------+
| constant name | meaning |
+===============+====================================================+
| BYTE | a type with at least 8 bits in it, usually a char |
| WORD | a type with at least 16 bits in it |
| LONG | a type with at least 32 bits, used for pointers |
| NULL | a value assigned to pointers pointing nowhere |
+---------------+----------------------------------------------------+
+---------------+-----------------------------------------------------+
| macro name | meaning |
+===============+=====================================================+
| Pterm | gemdos $4c, terminate process and return to caller |
| Cconis | gemdos $0b, console character available ? |
| Crawcin | gemdos $07, get a raw character from console |
| Cnecin | gemdos $08, get a not-so raw character from console |
| Bconout | bios $03, output a character to a device |
| Bconstat | bios $01, get input device status |
| Bconin | bios $02, input a character from a device |
| Supexec | xbios $26, execute function in supervisor mode |
+---------------+-----------------------------------------------------+
Screen updating.
The package defines a data type called WINDOW, which represents what a
section of the terminal may eventually look like. It can be used as a
scratch-pad onto which you can make changes. Only after calling
the function refresh() or wrefresh() an attempt will be made by the package
to make things on the screen look like the things you specified in the
window. Information contained in the window include not only its contents,
but also its size, its starting point and various other information. Two
standard window are defined after initialization of the package, namely
curscr, which constitutes the package's idea of what the screen looks like,
and stdscr, which is a default window to make changes on. It is advised not
to address curscr directly, but first to make changes on another window and
then to call refresh() or wrefresh() to make curscr look like the other
window. Making a change on curscr results in immediate execution of the
change, this greatly reduces any chances of optimization and therefore results
in a sizeable loss of speed ( unless you know what you're doing, of course ).
Naming conventions.
All output and input functions can be used with any window. These functions
have two variants, one to act on the default screen stdscr, and another to
act on any window. An example is the function addch(), which adds a character
to stdscr. The variant, which adds a character to a window w is called
waddch() and takes w as an argument. This convention is used throughout the
package. The routines which do not adhere to this convention always take a
window as an argument.
Apart from the w-convention some functions also take a mv- prefix.
Ordinarily one moves the current coordinates of a window by calling
the move or wmove function. Preceding an I/O function by mv first moves
the current coordinates and then performs the I/O function. In this way
one can write the sequence :
move(y,x) ;
addch('Q') ;
as :
mvaddch(y,x,'Q') ;
and the sequence :
wmove(win,y,x) ;
waddch(win,'W') ;
may be replaced by :
mvwaddch(win,y,x,'W') ;
You may have noticed the following other conventions :
1. If a window must be specified as a parameter, it is always the first
parameter.
2. Coordinates are specified as (y,x) pairs, where y is in the up/down
direction, and x in the letf/right direction, the coordinate (0,0) is
in the upper-left corner of the window.
Programming with curses.
The following sections deal with programming with the library.
First of all curses should be initialized first. This is done by a call to
initscr(). On return curses will have initialized the screen to a state known
by curses, and have initialized curscr and stdscr, whereas prior to the
initscr() call, any reference to curscr or stdscr will result in bombs.
After calling initscr() you should perform any terminal status changing
routines like crmode() or nonl(), although these may be performed anytime
when curses is active. After that you can set up the screen status using
functions like leaveok() and scrollok() or allocate new windows with newwin()
or subwin(), delete them with delwin().
Calling initscr() again will either result in a redraw of the screen or
another initialization step when the variables LINES or COLS have changed.
T